package band.wukong.practice.javase.core.reflect;

import band.wukong.practice.util.mess.ReflectUtils;

import java.lang.reflect.Field;

public class ReflectTester {

    public static void main(String[] args) throws Exception {
        ReflectTester test = new ReflectTester();

        test.getPackageName(Class.forName("ReflectTester"));

    }

    public void getPackageName(Class c) throws ClassNotFoundException {
        Package p = c.getPackage();
        if (p != null) {
            System.out.println("package " + p.getName());
        }
    }

    public void getImport(Class c) {
        Field[] fieldArray = c.getDeclaredFields();
        for (Object obj : fieldArray) {
            Field f = (Field) obj;

        }
    }

    public void getProperties() throws Exception {
        String[] params = {"Sailor"};
        Object boy = ReflectUtils.newInstance("Boy", params);
        if (ReflectUtils.isInstance(boy, Boy.class)) {
            //String name = (String)ReflectUtil.getPrivateProperty(boy, "name");
            String name = (String) ReflectUtils.invokeMethodWithNoParam(boy, "getName");
            System.out.println(name);
        }
    }


}
